/*
cond
条件变量
类似Java的ReentrantLock newCondition()
*/
package main

import (
	"fmt"
	"sync"
	"time"
)

func main() {
	cond := sync.NewCond(&sync.Mutex{})
	var flag bool
	go func() {
		time.Sleep(1 * time.Second)
		cond.L.Lock()
		flag = true
		// 唤醒一个等待的goroutine
		//cond.Signal()
		// 唤醒所有等待的goroutine
		cond.Broadcast()
		cond.L.Unlock()
	}()

	fmt.Println("waiting")
	cond.L.Lock()
	for !flag {
		cond.Wait()
	}
	cond.L.Unlock()
	fmt.Println("done")
}
